<template>
  <div>
    <el-form
      :inline="true"
      :model="formData"
      size="small"
      class="demo-form-inline"
    >
      <el-form-item prop="name" label="用户名">
        <el-input
          v-model="formData.name"
          clearable
          placeholder="用户名"
        ></el-input>
      </el-form-item>
      <el-form-item prop="mobile" label="手机号码">
        <el-input
          v-model="formData.mobile"
          clearable
          placeholder="手机号码"
        ></el-input>
      </el-form-item>
      <el-form-item prop="province" label="省区">
        <el-input
          v-model="formData.province"
          clearable
          placeholder="省区"
        ></el-input>
      </el-form-item>
      <el-form-item prop="city" label="市区">
        <el-input
          v-model="formData.city"
          clearable
          placeholder="市区"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tableData">
      <el-table-column prop="name" label="用户名" width="180">
      </el-table-column>
      <el-table-column prop="mobile" label="手机号码" width="180">
      </el-table-column>
      <el-table-column prop="createTime" label="申请时间" width="180">
      </el-table-column>
      <el-table-column prop="province" label="省区/城市" width="300">
        <template slot-scope="scope">
          {{ scope.row.province }}/{{ scope.row.city }}
        </template>
      </el-table-column>
      <el-table-column prop="auditFlag" label="状态" width="180">
        <template slot-scope="scope">
          {{ scope.row.auditFlag === 0 ? "待审" : "已通过" }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <div v-if="scope.row.auditFlag === 0">
            <el-button
              @click="clickStatus(scope.row.id, 4)"
              type="success"
              size="mini"
              >同意</el-button
            >
            <el-button
              type="danger"
              size="mini"
              @click="clickStatus(scope.row.id, 3)"
              >拒绝</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <v-pagination :formData="formData" @load="CityUser"></v-pagination>
  </div>
</template>
<script>
import { cityUser, queryManager } from "@/api/cityUser";
import pagination from "@/components/pagination";
export default {
  components: {
    vPagination: pagination,
  },
  data() {
    return {
      formData: {
        name: "",
        mobile: "",
        province: "",
        city: "",
        pageNo: 1,
        pageSize: 10,
        total: 0,
      },
      loading: true,
      tableData: [],
    };
  },
  created() {
    this.CityUser();
  },
  methods: {
    CityUser() {
      this.loading = true;
      cityUser(this.formData).then((res) => {
        this.loading = false;
        this.tableData = res.data.resultData.lists;
        this.formData.total = res.data.resultData.count;
      });
    },
    clickStatus(id, status) {
      switch (status) {
        case 4:
          this.$confirm("是否同意该用户为城市盟主？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.QueryManager(id, status);
            })
            .catch(() => {});
          break;

        default:
          this.$confirm("是否拒绝该用户为城市盟主？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.QueryManager(id, status);
            })
            .catch(() => {});
          break;
      }
    },
    QueryManager(id, status) {
      queryManager({ id: id, cityUser: status }).then((res) => {
        if (res.data.resultStatus) {
          this.$message.success(res.data.errorMessage);
          this.CityUser();
        } else {
          this.$message.error(res.data.errorMessage);
        }
      });
    },
    onSubmit(formName) {
      this.formData.pageNo = 1;
      this.formData.pageSize = 10;
      this.formData.total = 0;
      this.CityUser();
    },
  },
};
</script>
